<?php
namespace Admin\Controller;
use Think\Controller;
class CommonController extends Controller {
    public function _initialize(){
        if($_SESSION['uid']){
            $this->uid =$_SESSION['uid'];
        }else{
            $url = U('Login/index');
            header("Location: $url");
        }
    }

    //AJAX -- 根据所选省份，获取所有市
    public function city()
    {
        $city_list = M('area')->field('code,name')->where(array('parentId' => I('province')))->select();
        echo json_encode($city_list);
    }

    //AJAX -- 根据所选城市，获取所有县区
    public function county()
    {
        $county_list = M('area')->field('code,name')->where(array('parentId' => I('city')))->select();
        echo json_encode($county_list);
    }

    //AJAX -- 根据所选县区，获取所有乡镇
    public function town()
    {
        $county_list = M('area')->field('code,name')->where(array('parentId' => I('county')))->select();
        echo json_encode($county_list);
    }
}